package com.ruoyi.quartz.util;

import java.util.List;

import com.aliyun.tea.TeaException;

public class AliyunSmsUtils {

	/**
     * 使用AK&SK初始化账号Client
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // 必填，您的 AccessKey ID
                .setAccessKeyId("LTAI5tND98dPsnr9JVpR3WVv")
                // 必填，您的 AccessKey Secret
                .setAccessKeySecret("15jQulZtXqn3zhxTeC0ply6agjFd2b");
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }
    
    /**
     * aliyun Api调用短信接口
     * @param phones 
     * @return
     * @throws Exception
     */
    public static Boolean returnSmsDqtx(List<String> phones) throws Exception{
    	
    	String phonelis = "";//电话数组
    	String signNamelis = "";//签名数组
    	String templateCode = "SMS_460650327";//模板编号
    	for(String phone:phones){
    		phonelis+="\""+phone+"\",";
    		signNamelis+="\"湖北城志电力\",";
    	}
    	
        // 工程代码泄露可能会导致AccessKey泄露，并威胁账号下所有资源的安全性。以下代码示例仅供参考，建议使用更安全的 STS 方式，更多鉴权访问方式请参见：https://help.aliyun.com/document_detail/378657.html
        com.aliyun.dysmsapi20170525.Client client = AliyunSmsUtils.createClient("accessKeyId", "accessKeySecret");
        com.aliyun.dysmsapi20170525.models.SendBatchSmsRequest sendBatchSmsRequest = new com.aliyun.dysmsapi20170525.models.SendBatchSmsRequest()
                .setPhoneNumberJson("["+phonelis+"]")
                .setSignNameJson("["+signNamelis+"]")
                .setTemplateCode(templateCode);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // 复制代码运行请自行打印 API 的返回值
            client.sendBatchSmsWithOptions(sendBatchSmsRequest, runtime);
        } catch (TeaException error) {
            // 如有需要，请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
            return false;
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 如有需要，请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
            return false;
        } 
    	
		return true;
    }
}